﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace CoolnessWidget
{
    /// <summary>
    /// Interaction logic for CoolView.xaml
    /// </summary>
    public partial class CoolView : UserControl
    {
        public CoolView()
        {
            InitializeComponent();
            score = previousScore = 25;
        }

        private int previousScore;
        private int score;

        public int Score
        {
            get
            {
                return score;
            }
            set
            {
                if (value >= 0 && value <= 40)
                {
                    previousScore = score;
                    score = value;
                    ComputeScore();
                }
            }
        }

        private void ComputeScore()
        {
            if (previousScore / 10 != score / 10)
            {
                Storyboard storyboard = (Storyboard)this.FindResource("ChangeCoolFace");
                Storyboard.SetTargetName(storyboard.Children[0], string.Format("image{0}", previousScore / 10 + 1));
                Storyboard.SetTargetName(storyboard.Children[1], string.Format("image{0}", score / 10 + 1));
                this.BeginStoryboard(storyboard);
            }
        }

    }
}
